// 封装ajax
function ajax(obj) {
	obj = obj || {};
	obj.method = obj.method.toUpperCase() || 'POST'; // 请求方式
	obj.url = obj.url || ''; // 请求路径
	obj.async = obj.async || true; // 是否异步
	obj.data = obj.data || null; // 发送的数据
	obj.success = obj.success || function() {
	}; // 响应成功的回调函数
	obj.error = obj.error || function() {
		alert('服务器繁忙！')
	};
	if (XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else {
		xhr = new ActiveXObject('Microsoft.XMLHTTP');
	}
	var params = [];
	for ( var key in obj.data) {
		params.push(key + '=' + obj.data[key]);
	}
	var postData = params.join('&');
	if (obj.method.toUpperCase() === 'POST') {
		xhr.open(obj.method, obj.url, obj.async);
		xhr.setRequestHeader('Content-Type',
				'application/x-www-form-urlencoded;charset=utf-8');
		xhr.send(postData);
	} else if (obj.method.toUpperCase() === 'GET') {
		if(postData === "" || postData === undefined || postData === null){
			xhr.open(obj.method, obj.url, obj.async);
		}else{
			xhr.open(obj.method, obj.url + '&' + postData, obj.async);
		}
		xhr.send(null);
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 200) {
			obj.success(xhr.responseText);
		}
	}
}